namespace SimpleWebServices.Web.UI.Html.Validation
{
    using System;
    using SimpleWebServices;
    using SimpleWebServices.Data;
    using SimpleWebServices.Web.UI.Html.Elements;
    using Xunit;

    public sealed class RadioFieldsetValidatorFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<RadioFieldsetValidator>()
                .DerivesFrom<Validator>()
                .IsConcreteClass()
                .IsSealed()
                .HasDefaultConstructor()
                .Result);
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new RadioFieldsetValidator());
        }

        [Fact]
        public void ctor_IInnerElements()
        {
            Assert.NotNull(new RadioFieldsetValidator(new Label()));
        }

        [Fact]
        public void ctor_IInnerElementsNull()
        {
            Assert.NotNull(new RadioFieldsetValidator(null as IInnerElements));
        }

        [Fact]
        public void op_Validate_IElement_false()
        {
            Fieldset fieldset = (
                "<fieldset>" +
                    "<input id='choice' type='radio' />" +
                "</fieldset>").Deserialize<Fieldset>();

            Assert.False(new RadioFieldsetValidator(new Label()).Validate(fieldset));
        }

        [Fact]
        public void op_Validate_IElement_true()
        {
            Fieldset fieldset = (
                "<fieldset>" +
                    "<div>" +
                        "<input id='choice' type='radio' value='123' checked='checked' />" +
                    "</div>" +
                "</fieldset>").Deserialize<Fieldset>();

            Assert.True(new RadioFieldsetValidator(new Label()).Validate(fieldset));
        }

        [Fact]
        public void op_Validate_IElementNotFieldset()
        {
            Assert.Throws<ArgumentOutOfRangeException>(() => new RadioFieldsetValidator().Validate(new Division()));
        }

        [Fact]
        public void op_Validate_IElementNull()
        {
            Assert.Throws<ArgumentNullException>(() => new RadioFieldsetValidator().Validate(null as IElement));
        }
    }
}